﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace AutoFormular
{
    public class PeoplePusher : IHttpHandler
    {
        public bool IsReusable
        {
            //Må der initialiseres flere instanser af denne klasse ?
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string input = context.Request.Form["Name"];

            NORTHWNDEntities db = new NORTHWNDEntities();
            var res = from i in db.Employees
                      where i.FirstName.StartsWith(input)
                      orderby i.FirstName
                      select new { i.FirstName, i.LastName, i.Address, i.HomePhone };

            context.Response.ContentType = "application/json";
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonstr = serializer.Serialize(res);
            context.Response.Write(jsonstr);

        }
    }
}